package hotel.meituan.oversea.biz.task;

import hotel.base.oversea.utils.DateUtil;
import hotel.meituan.oversea.api.entity.SysApiLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;


@Slf4j
@Component
public class MeituanSaveApiLogTask {
    private String timestamp = "Msalt"+String.valueOf(System.currentTimeMillis());

    @Autowired
    private RestTemplate restTemplate;

    //@Async 标识这个方法异步执行，可返回void或Future
    @Async
    public void execute(SysApiLog sysApiLog){
        //log.info("MeituanSaveApiLogTask {} >>>>>>>>> 异步线程 保存系统日志  开始执行时间：{}",timestamp,DateUtil.getNowTime());

        try{
            //发起请求
//            Result response = RestTemplateUtils.post(CommonUrlConstants.ADMIN_HOST+"/sysApiLog/save",JSON.toJSONString(sysApiLog),restTemplate);
//            if(CommonConstants.SUCCESS==response.getCode()){
//            }else{
//                log.error("////////////////////////MeituanSaveApiLogTask 保存日志到sysApiLog返回失败：sysApiLog={},response={}",JSON.toJSONString(sysApiLog),JSON.toJSONString(response));
//            }
        }catch (Exception e){
            log.error("MeituanSaveApiLogTask {} >>>>>>>>> 异步线程 保存系统日志  异常catch：{},{}",timestamp,DateUtil.getNowTime(),e.getMessage());
            e.printStackTrace();
        }


    }


}
